package com.aos.controller;

import com.aos.dto.parameters.SynchroUserParameter;
import com.aos.service.user.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName SynchroDataController
 * @Description:数据同步控制器
 * @Author wumingwang
 * @Date 2018/9/19 13:55
 * @Version 1.0
 */
@Slf4j
@RestController
@Api(value = "SynchroData Controller", tags = {"数据同步接口,服务内部调用"})
public class SynchroDataController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "同步用户", notes = "同步用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentUsername", value = "父账号登录名", dataType = "String"),
            @ApiImplicitParam(name = "username", value = "登录名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "password", value = "密码(可不填，默认123456)", dataType = "String"),
            @ApiImplicitParam(name = "name", value = "用户名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "email", value = "邮箱", dataType = "String"),
            @ApiImplicitParam(name = "mobile", value = "手机号码", dataType = "String"),
            @ApiImplicitParam(name = "sex", value = "性别【男:1;女:2;未知:3】", dataType = "String"),
            @ApiImplicitParam(name = "appcode", value = "应用编码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "group", value = "用户所在组织", dataType = "String"),
            @ApiImplicitParam(name = "comment", value = "备注", dataType = "String"),
            @ApiImplicitParam(name = "state", value = "用户状态【1:可用；2不可用】", dataType = "String"),
            @ApiImplicitParam(name = "dataType", value = "同步类型，新增：insert，更新：update，删除：delete",required = true, dataType = "String"),
            @ApiImplicitParam(name = "oldUsername", value = "旧用户登录名（更新时必填）", dataType = "String"),
            @ApiImplicitParam(name = "roleIds", value = "角色ID数组", dataType = "Long[]"),
    })
    @PostMapping("/synchrodata/v1/user")
    public Object synchroUser(@Validated @RequestBody SynchroUserParameter user){
        return userService.synchroUser(user);
    }
}
